package org.example;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.Reader;

public class GetterTest {
    @Test
    public void getter() throws Exception{
        File file = new File("D:\\JDBC_project\\JDBC_Demo\\src\\main\\resources\\data-file-simple");
        FileReader reader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(reader);
        while (bufferedReader.ready()){
            String line = bufferedReader.readLine();
//            System.out.println(line);
            String[] arr = line.split("\\|");
            switch (arr[3]){
                case "16":
                    System.out.println("温湿度");
                    String temp = arr[6].substring(0,4);
                    int temp_int = Integer.parseInt(temp,16);
                    double temp_real = (temp_int*(0.00268127F))-46.85F;
                    System.out.println("温度："+temp_real);
                    String humi = arr[6].substring(4,8);
                    int humi_int = Integer.parseInt(humi,16);
                    double humi_real = (humi_int*0.00190735F)-6;
                    System.out.println("湿度："+humi_real);
                    break;
                case "256":
//                    System.out.println("光照强度");
                    String light = arr[6].substring(0,4);
                    int light_int = Integer.parseInt(light,16);
                    System.out.println("光照强度："+light_int);
                    break;
                case "1280":
//                    System.out.println("二氧化碳浓度");
                    String co2 = arr[6].substring(0,4);
                    int co2_int = Integer.parseInt(co2,16);
                    System.out.println("二氧化碳浓度："+co2_int);
                    break;
                default:
                    System.out.println("数据格式有误，请排查");
            }

        }
    }
}
